1307 stories
·
0 followers

A hypothetical redesign of System.Diagnostics.Process to avoid confusion over properties that are valid only when you are the one who called Start

2 Shares

Some time ago, I noted that the Process.Standard­Output property is an attractive nuisance because it is valid only on Process objects that you called Start on. You can’t just grab any old Process object and try to access its standard handles.

Others in the comments had their ideas on how to remove the confusion. Here’s mine. The principle is that the properties and methods of the Process object should be valid for all instances of the Process class. If a property or method is valid only conditionally, then either move it to a place that is accessible only if the condition is met, or get rid of it entirely if it adds no value.

The standard handles are the three properties that make sense only for Process objects that were created by the static Start method. There are also four methods related to those standard handles, as well as two events. Move them all to a new class, call it Process­Start­Result:

class ProcessStartResult
{
    public Process Process { get; }
    public System.IO.StreamWriter StandardInput { get; }
    public System.IO.StreamWriter StandardOutput { get; }
    public System.IO.StreamWriter StandardError { get; }

    public void BeginOutputReadLine();
    public void CancelOutputReadLine();
    public event DataReceivedEventHandler? OutputDataReceived;

    public void BeginErrorReadLine();
    public void CancelErrorReadLine();
    public event DataReceivedEventHandler? ErrorDataReceived;
}

Change the signature of all the overloads of the Start method so that they return a Process­Start­Result instead of a Process. Now it is impossible to do anything with the standard handles from a process you didn’t start: If you didn’t start the process, then you don’t have a Process­Start­Result. This removes the confusion that existed in the original attempt to have a process read from its own standard output.

This follows a principle I wrote about earlier: To force the developer to do things in a certain order, make the second step dependent on something produced by the first step. In this case, we want to force the developer to call Start before they use the standard handles, so we put the members related to the standard handles on a thing that you can obtain only by calling Start.

Next, remove the Start­Info property entirely. It serves two purposes:

  • Prior to calling the Start method, it provides a convenient pre-made Process­Start­Info.
  • After calling the Start method, it holds a copy of the parameters that you passed to the Start method.

The first purpose is just to cover for people who are too lazy to write the new keyword. So don’t be lazy. Write new Process­Start­Info().

The second purpose doesn’t tell you anything you don’t already know, since you are the one who passed the parameters to the Start method in the first place. If they are so important to you, you can save them yourself.

Removing the Start­Info avoids confusion over whether the properties in it describe the process you want to start, or whether they describe a process that has already started. (And often, it describes neither!)

I think that takes care of the largest source of confusion over the proper use of the Process class.

The post A hypothetical redesign of <CODE>System.<WBR>Diagnostics.<WBR>Process</CODE> to avoid confusion over properties that are valid only when you are the one who called <CODE>Start</CODE> appeared first on The Old New Thing.

Read the whole story
Share this story
Delete

US's big bet on quantum computing may not be entirely legal

1 Share

Last week, the US government announced $2 billion in investments in quantum computing companies, allocating $100 million each to a range of startups in exchange for equity in the companies. Those could be make-or-break investments for many companies that are likely years away from a product that could see widespread use. But a member of the US Congress is now arguing that those deals are illegal, as Congress did not allocate the money for this purpose—instead, it was meant to support public research in semiconductors.

But the biggest chunk of money would go to a company that likely wouldn't exist if it weren't for the government's backing. Anderon will be set up with a billion dollars each from IBM and the government and will inherit personnel and IP from IBM. It will serve as a foundry for fabricating quantum processing units and will contract its services out to IBM and any other company that wants access to cutting-edge hardware.

Is any of this legal?

Zoe Lofgren (D–Calif.), the ranking member of the House Science, Space, and Technology Committee, made it clear that she is not happy with how the government is using its money to support this technology.

“This announcement is illegal and troubling on so many levels,” Lofgren said one day after the announcement, pointing out that the money being used for the deal comes from the CHIPS and Science Act, which was passed during the Biden administration and was allocated "specifically for microelectronics R&D, with a focus on semiconductor technology."

That technology overlaps only partially, at best, with what's used in quantum processors. In addition, Lofgren says the money was allocated to foster public/private research partnerships, which these deals most decidedly are not. Finally, she noted that the largest sum of money will go to IBM, and she suggested that a former IBM executive (Dario Gil, current Under Secretary for Science at the Department of Energy) was involved in the negotiations that led to this deal.

None of this, she noted, means that quantum processing technology is a bad investment or that any of these companies are unworthy of support. She just argues that doing so would require Congress to allocate the money to do so.

At this point, however, it's not obvious how to stop the deal. A lawsuit is the obvious choice, but that would require a party with standing to sue. It's possible that a company that might otherwise have used the money for the intended research (a public-private partnership focused on electronics) could argue that it has been harmed by the diversion of the funds to a different field. But that argument would likely take so long to sort out in court that all the money would have been spent by then.

A quantum foundry

One thing that has helped IBM stay at the forefront of quantum computing is its access to in-house materials scientists and fabrication capabilities. Those resources have enabled the company to manufacture chips that test alternate designs and rapidly iterate and refine successes—an advantage powerful enough that Google also decided to open its own fabrication facility.

Given that, it's somewhat surprising that IBM is choosing to spin these efforts into a separate company, called Anderon, which it will fund with $1 billion, alongside an equal government investment. According to the company's announcement, it will also be handing over "significant intellectual property, assets, and a skilled workforce" to the newly launched company. The result could resemble TSMC, with the company fabricating quantum chips for firms that submit a design and pay the cost.

Not just any companies, though. IBM has specialized in producing transmons, a specific type of hardware that can host a qubit. But it's not the only game in town. Other companies, including a number funded in the same announcement, are using technologies that host qubits in very different hardware or no hardware at all. This is very much a case of using government money to favor a specific category of technology.

That said, the move will likely be good for the broader field. A significant number of companies are designing transmon-based hardware that differs in important ways from IBM's approach. But they're stuck producing a limited number of test samples in fabs that may not specialize in quantum hardware, or where they have to compete with academic users for fabrication time. The launch of Anderon means those companies should now be able to access higher-quality hardware and rapidly iterate on designs. It will make testing their ideas less dependent on whether the fab they're using produces high-quality hardware.

For IBM, this may reflect a confidence that the company has already extracted the major benefits of rapid iteration and is safely ahead of its competition. Jay Gambetta, the leader of IBM's quantum computing efforts, has told Ars that the current hardware error rates for its chips are where they need to be to move forward with large-scale computing. Lower errors would be better, and the company has some ideas for how to achieve them, but they're not strictly necessary for the next few years of development.

If that's the case, why not have the government assume half the cost of staff and facilities?

What's the long term?

We're likely still several years away from useful error-corrected quantum computing, and closer to a decade from tackling some of the large, complicated problems where quantum computers could see widespread use. At the moment, though, it's still unclear which technology (or technologies) will ultimately get us there first or prove capable of scaling for a decade or more. Keeping some of these companies viable for the next few years could be critical to ensuring that these technologies receive a full evaluation against those standards.

At the same time, the deal all but guarantees we'll be investing in companies that are certain to fail. In the past, that has often devolved into cheap political point-scoring.

Longer term, it's not entirely obvious how large Anderon's target market will be. With a large number of startups, there will likely be a strong demand for these sorts of tips as companies test design variants and configurations. But even assuming the market settles on transmons, it's not clear how large the annual need for these chips will be.

Transmons must be operated at milliKelvin temperatures, and large-scale, error-corrected quantum computers will likely require chaining together chips housed in multiple refrigerated containers. That will likely mean most of the hardware in use will sit in just a few data centers and be accessed online (as it is currently). Consequently, there's a real potential for a boom-and-bust pattern in the market for these chips.

Read full article

Comments



Read the whole story
Share this story
Delete

Researchers Say the Worst Climate Future is Less Likely. But the Best One is Also Slipping Away

1 Share
Citing new research, the Associated Press reports that "modest gains in the fight to curb climate change have dialed back the most catastrophic of future heating." That's the good news. But the same research "also confirmed that there's no chance to limit warming to the international goal set in 2015." Researchers' new list of seven plausible carbon pollution scenarios for the future are pushing aside two staples of climate policy: the extremes on either end. The extremes have become less probable in the past several years because of how we power our world. Carbon dioxide, released from the burning of gas, oil and coal, is chiefly responsible for warming. Increasing use of green energies, like solar, wind and geothermal, which don't emit carbon dioxide, have lowered top end carbon pollution projections. However, because those changes haven't been fast enough, the bottom end projections have risen. The Paris climate agreement in 2015 set a goal of limiting warming to 1.5 degrees Celsius (2.7 degrees Fahrenheit) since pre-industrial times, or the mid-1800s, giving rise to the mantra "1.5 to stay alive," but now scientists say that even their best case scenario still shoots past that signature temperature mark. On the other end, those same new scenarios no longer include the coal-heavy future that would lead to 4.5 degrees Celsius (8.1 degrees Fahrenheit) of warming by 2100, a scary scenario that many scientific studies used in their future projections. The new proposed worst case scenario has an end-of-the-century warming of about 3.5 degrees Celsius (6.3 degrees Fahrenheit), a full degree (1.8 degrees Fahrenheit) less than the old scenario, while the updated best case future is a couple tenths of a degree Celsius (0.36 degrees Fahrenheit) warmer than previously theorized, squeezing past the Paris goal, said climate scientist Detlef Van Vuuren of Utrecht University, lead author of a recent study laying out future scenarios. "There is kind of a narrowing of the futures. It cannot be as bad as we thought, but it cannot be as good as we hoped," said Johan Rockström, director of the Potsdam Institute for Climate Impact Research in Germany. The scenarios include a "middle" one where by the end of the century the world warms 3 degrees Celsius (5.4 degrees Fahrenheit) above pre-industrial times, which is roughly the path society is currently on, scientists said... Because carbon pollution keeps rising globally and stays in the atmosphere for about century, the best case scenario is for warming to shoot past the 1.5 degree mark, peak at 1.7 degrees Celsius (3.1 degrees Fahrenheit) for maybe as long as 70 years, and eventually somehow come back down below 1.5 degrees if a technology can be designed to remove massive amounts of carbon from the air, said nine of the 10 scientists interviewed for this article. The world is warming at a pace of a tenth of a degree Celsius (nearly 0.2 degrees Fahrenheit) every five years, they said.

Read more of this story at Slashdot.

Read the whole story
Share this story
Delete

Why do you say that a COM STA thread must pump messages if I see sample code creating STA threads and not pumping messages?

1 Share

One of the rules for COM single-threaded apartments (STA) is that the thread in that apartment must pump messages. But we also see code that initializes COM in single-threaded mode but which never pumps messages. Consider this function from the XML DOM object dynamic creation sample:

int __cdecl wmain()
{
    HRESULT hr = CoInitialize(NULL);
    if (SUCCEEDED(hr))
    {
        dynamDOM();
        CoUninitialize();
    }
    return 0;
}

The Co­Initialize function initializes COM in single-threaded apartment mode, and then the program does some work, and then it uninitializes COM, and it never pumps messages. What gives? Shouldn’t there be a message loop?

The rule about single-threaded apartments is that they must pump messages when idle. If they are busy doing something, then clearly they can’t pump messages because they are busy doing something!¹

If your thread initializes COM as a single-threaded apartment, and then does a bunch of work, and then uninitializes COM, then that’s great. Your thread was never idle, so it never got a chance to pump messages. (Though if your thread made COM calls out to other threads, COM will pump messages while waiting for the reply, so it did pump messages while the thread was idle.)

Failing to pump messages when idle means that when another thread wants to communicate with your thread, it never gets a response. Now, if your thread is busy, then it’s fine that the other thread doesn’t get a response from you—you’re busy with something else after all. But if you are in a single-threaded COM apartment and you have finished with whatever you’re doing, you need to pump messages to see if there’s any work that COM wants you to do, or you need to uninitialize COM.

Now, you might say, “Look, my thread doesn’t create any windows, and it doesn’t do any cross-thread COM stuff, so who cares that it’s not pumping messages? It’s not like anybody is ever going to ask this thread to do anything, and since it created no windows, nobody could send it anything.”

Aha, but you see, your thread did create a window. When you initialize a thread as a single-threaded apartment, COM creates a window. It creates this window so that it can receive inbound requests for the thread to do something. If you don’t pump messages, then you have a thread blocked not pumping messages, which will jam up window broadcasts.

¹ An intentionally obtuse interpretation of the rule that “an STA thread must pump messages” would be that your thread can’t do anything except call GetMessage and DispatchMessage! Because any other line of code would not be “pumping messages”.

The post Why do you say that a COM STA thread must pump messages if I see sample code creating STA threads and not pumping messages? appeared first on The Old New Thing.

Read the whole story
Share this story
Delete

How do I use Win32 structures from the Windows Runtime?

2 Shares

The Windows Runtime attempts to provide a language-independent interface for Windows APIs: The ABI is consistent across the Windows Runtime, and the APIs themselves are described via metadata, allowing each language to map the Windows Runtime concepts into concepts that are more natural for each target language. For example, the Windows Runtime DateTime maps to a corresponding date-time type for each target language, like std::chrono::time_point for C++ or Date for JavaScript. A cost of this goal is that the expressiveness of the Windows Runtime is constrained by the desire to make all the features available to all languages. For example, there are no raw pointers in the Windows Runtime.

Win32 structures defined in classic C/C++ header files are not part of the Windows Runtime. So in a literal sense, you can’t use them from the Windows Runtime.

But you can fake it.

You can declare a shadow structure in the Windows Runtime that has the same layout as the classic Win32 structure you want to use. For example, you could declare your own Win32Point structure:

struct Win32Point
{
    Int32 X;
    Int32 Y;
};

Note that the Windows Runtime has its own conventions for some things that in Win32 are represented by structures. For example, the PROPERTYKEY structure is represented conventionally in the Windows Runtime in its string form. You can use functions like PSPropertyKeyFromString and PSStringFromPropertyKey to convert between them.

The post How do I use Win32 structures from the Windows Runtime? appeared first on The Old New Thing.

Read the whole story
Share this story
Delete

At Least 80% Responsibility For Ill Health In Old Age Down to Individual, Study Says

1 Share
A new Oxford Longevity Project report argues that individuals bear at least 80% of the responsibility for ill health in old age. "The report (PDF), launched at the Smart Ageing Summit in Oxford last week, argues that individuals have far greater control over their longevity than is commonly understood," reports The Guardian. "The authors call on the government to take legislative action on alcohol comparable to restrictions on smoking." From the report: Living Longer, Better -- the Oxford Longevity Project's first Age-less report -- was co-authored by an interdisciplinary panel of UK-based experts in medicine, physiology, ageing and education policy. It was sponsored by Oxford Healthspan. The report's authors, Sir Christopher Ball, Sir Muir Gray, Dr Paul Ch'en, Leslie Kenny and Prof Denis Noble, present the figure of 80% as a conservative estimate. [...] The claim, however, has been described as simplistic and said to neglect wider arguments about whether people are genuinely in control of individual choices when it comes to issues including poverty, pollution and healthcare access. [...] Ball, however, pointed to research including the Landmark Twins Study, where researchers concluded at least 75% of human lifespan is determined by environmental and modifiable lifestyle factors. He also cited large-scale analysis led by Oxford Population Health using data from nearly 500,000 UK Biobank participants which found that environmental exposures and habits carry far greater weight in premature death and biological ageing than inherited genetics. The report's recommendations include avoiding processed foods, abstaining entirely from alcohol, prioritising sleep, not eating after 6.30pm, and cultivating what it calls "a not-meat mindset." On alcohol, it takes a position more forthright than current government guidance. "Alcohol is toxic, don't drink it," said Ball. "The report bravely says so -- whereas the government is afraid to tell the public the truth."

Read more of this story at Slashdot.

Read the whole story
Share this story
Delete
Next Page of Stories